package com.zhs.smartmall.product.service.impl;


import com.zhs.smartmall.product.model.PmsSkuImages;
import com.zhs.smartmall.product.dao.PmsSkuImagesDao;
import com.zhs.smartmall.product.service.IPmsSkuImagesService;
import com.zhs.smartmall.product.dto.PmsSkuImagesDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author zhenghuisheng
 * @since 2023-11-11
 */
@Service
@Slf4j
public class PmsSkuImagesServiceImpl extends ServiceImpl< PmsSkuImagesDao, PmsSkuImages> implements IPmsSkuImagesService {

    @Resource
    private PmsSkuImagesDao pmsSkuImagesDao;

    @Override
    @Transactional
    public R addOrUpdate(PmsSkuImagesDto pmsSkuImagesDto) {
        if (BeanUtil.isEmpty(pmsSkuImagesDto)) throw new ServiceException("数据不能为空");
        PmsSkuImages pmsSkuImages = new PmsSkuImages();
        BeanUtil.copyProperties(pmsSkuImagesDto,pmsSkuImages);
        if (pmsSkuImagesDto.getId() == null){
            pmsSkuImagesDao.insert(pmsSkuImages);
            return R.ok("数据插入成功");
        }else {
            pmsSkuImagesDao.updateById(pmsSkuImages);
            return R.ok("数据更新成功");
        }
    }
}